package org.huangxiaozhe.adventure;

import org.huangxiaozhe.adventure.common.ConstantUtil;

/**
 * 
 * ����Ϊ������������Ʒ���ֵ���
 *
 */
public class GameViewBackGroundThread extends Thread{
	
	int count=0;		//��¼֡��ñ������ڼ���֡����
	long startTime = System.nanoTime();	//��¼��ʼʱ�䣬�ñ������ڼ���֡����
	
	private int sleepSpan = 150;//˯�ߵĺ�����
	public int span = 1;//ͼƬ�ƶ��Ĳ���
	public boolean flag = false;//ѭ����־λ
	private boolean start = true;
	GameView gameView;//GameView������ 	
	
	public GameViewBackGroundThread(GameView gameView){//������
		this.gameView = gameView;
	}
	
	public void setFlag(boolean flag){//���ñ��λ
		this.flag = flag;
	}
	
	public void Start(){
		this.start = true;
	}
	
	public void Stop(){
		this.start = false;
	}
	
	public void run(){
		while(flag){
			if(start){
				gameView.backGroundIX -= span;
				if(gameView.backGroundIX <-ConstantUtil.screenLength){
					gameView.i = (gameView.i+1)%ConstantUtil.pictureCount;
					gameView.backGroundIX+=ConstantUtil.screenLength;
				}
			}
			
			try{
				Thread.sleep(sleepSpan);//˯��
			}catch(Exception e){//�����쳣
				e.printStackTrace();//��ӡ�쳣��Ϣ
			}
		}
	}
}